package com.hh.ssm.controller;

import java.util.List;

import com.hh.ssm.util.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hh.ssm.bean.Department;
import com.hh.ssm.bean.Employee;
import com.hh.ssm.util.ResponseMessage;
import com.hh.ssm.service.DepartmentService;
import com.hh.ssm.service.EmployeeService;
/**
 *
 * @author HH
 *
 */
@Controller
public class DepartmentController {

    @Autowired
    DepartmentService departmentService;

    /**
     * 需要导入Jackson包
     * @param pageNum
     * @return
     */
    @RequestMapping("/departments")
    @ResponseBody
    public ResponseMessage getAllDepartmentsJson(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        int pageSize = 3;
        PageHelper.startPage(pageNum, pageSize);
        List<Department> departments = departmentService.getAll();
        int navigatePages = 5;
        PageInfo pageInfo = new PageInfo(departments, navigatePages);
        ResponseMessage responseMessage = new ResponseMessage(false);
        return responseMessage.setSuccess(true).setData(pageInfo);
    }



    /**
     * 查询员工数据（分页查询）
     *
     * @return
     */
    @RequestMapping("/department")
    public String getAllDepartments(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            Model model) {
//
//        // 引入PageHelper分页插件进行分页
//        // 每页的记录数
        int pageSize = 8;
//
//        PageHelper.startPage(pageNum, pageSize);
//
//        List<Department> departments = departmentService.getAll();
//
//        int navigatePages = 5;
//
//
//        PageInfo pageInfo = new PageInfo(departments, navigatePages);
//
//        //System.out.println(pageInfo);
//
//        model.addAttribute("pageInfo", pageInfo);


        return "departments";

    }

}
